/*
** select.c for my_select in /home/nadali_t//local/svn/tek2ed/my_select
** 
** Made by thomas nadalie
** Login   <nadali_t@epitech.net>
** 
** Started on  Sun Nov 25 15:38:43 2012 thomas nadalie
** Last update Sun Nov 25 17:59:54 2012 thomas nadalie
*/

#include	"my.h"
#include        <unistd.h>
#include	<stdlib.h>
#include	<termios.h>
#include        <curses.h>
#include        <term.h>

int		catch_key(t_list *list)
{
  t_list	*(**functab)(t_list *list);
  int		*itab;
  struct termios	t;

  tcgetattr(0, &t);
  raw_mode(&t);
  if ((functab = malloc(sizeof(*functab) * 4 + 1)) == NULL)
    my_put_error("Malloc failed in function catch_key\n");
  if ((itab = malloc(sizeof(*itab) * 4 + 1)) == NULL)
    my_put_error("Malloc failed in function catch_key\n");
  init_functiontab(functab);
  init_keytab(itab);
  make_read(functab, itab, list);
  react_echo(&t);
  free(functab);
  free(itab);
  return (0);
}

t_list		*down_arrow(t_list *list)
{
  tputs(tgoto(tgetstr("ue", NULL), list->x, list->y), 1, my_putchar);
  my_putstr(list->arg);
  list = list->next;
  tputs(tgoto(tgetstr("cm", NULL), list->x, list->y), 1, my_putchar);
  tputs(tgoto(tgetstr("us", NULL), list->x, list->y), 1, my_putchar);
  my_putstr(list->arg);
  tputs(tgoto(tgetstr("ue", NULL), list->x, list->y), 1, my_putchar);
  return (list);
}

t_list		*up_arrow(t_list *list)
{
  /* tputs(tgoto(tgetstr("ue", NULL), list->x, list->y), 1, my_putchar); */
  list = list->prev;
  tputs(tgoto(tgetstr("cm", NULL), list->x, list->y), 1, my_putchar);
  /* tputs(tgoto(tgetstr("us", NULL), list->x, list->y), 1, my_putchar); */
  /* my_putstr(list->arg); */
  /* tputs(tgoto(tgetstr("ue", NULL), list->x, list->y), 1, my_putchar); */
  return (list);
}

t_list		*ctrl_c(t_list *list)
{
  clear_s();
  exit(0);
  return (list);
}

t_list		*ctrl_d(t_list *list)
{
  clear_s();
  exit(0);
  return (list);
}
